package com.lgt_enterprise_android.view.pages;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.Window;
import android.view.WindowManager;

import androidx.appcompat.app.AppCompatActivity;

import com.lgt_enterprise_android.BuildConfig;
import com.lgt_enterprise_android.Constant;
import com.lgt_enterprise_android.R;
import com.lgt_enterprise_android.utils.CommonUtil;
import com.lgt_enterprise_android.utils.PrefUtils;
import com.lgt_enterprise_android.utils.StringUtil;
import com.lgt_enterprise_android.view.MainActivity;

public class SplashActivity extends AppCompatActivity {

    private Context mContext;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        mContext=this;
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);

        CommonUtil.hideBottomUIMenu(this);

        String url=PrefUtils.getSharedPrefString(mContext,PrefUtils.url);
        if(!StringUtil.isEmpty(url)){
            Constant.URL=url;
        }

        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                String token=PrefUtils.getSharedPrefString(mContext, PrefUtils.TOKEN);

                if (!StringUtil.isEmpty(token)) {
                    Constant.token=token;

                    Intent intent = new Intent(mContext, MainActivity.class);
                    startActivity(intent);
                    finish();
                } else {
                    Intent intent = new Intent(mContext, LoginActivity.class);
                    startActivity(intent);
                    finish();
                }

            }
        }, BuildConfig.DEBUG ? 200 : 1500);

    }

    @Override
    public void onBackPressed() {
        //splashActivity下不允许back键退出
    }
}
